//
//  DBAccess.m
//  fmdbDemo
//
//  Created by rp.wang on 2017/9/22.
//  Copyright © 2017年 rp.wang. All rights reserved.
//

#import "DBAccess.h"

@implementation DBAccess

// 单例模式
+ (DBAccess *)sharedInstance
{
    static DBAccess *AccesssharedInstance = nil;
    static dispatch_once_t Accesspredicate;
    dispatch_once(&Accesspredicate, ^{
        AccesssharedInstance = [[DBAccess alloc] init];
    });
    return AccesssharedInstance;
}

-(void)insertdatafortableName :(infoModel *)infomodeldata
{
    [[DBHelper sharedInstance]inserttableName:infotableName nickName:infomodeldata.nickName infoID:Id userID:infomodeldata.userid sex:infomodeldata.sex department:infomodeldata.department];
}

///建表
-(void)CreateNewtable
{
    [[DBHelper sharedInstance]userInfoTableCreate];
}

///打开数据库
-(void)OpenServe
{
    [[DBHelper sharedInstance]CreateMyServer:serverName mydbName:DBName];
}

///给表里面添加字段
-(void)addstringfortbale :(NSString *)TableName addSrting:(NSString *)AddString
{
    [[DBHelper sharedInstance]AddcodeforTableView:TableName addcodeStr:AddString];
}

//查询表里的所有数据
-(NSArray *)readAllData
{
   return  [[DBHelper sharedInstance]loadalldata:infotableName];
}

/**
 *  通过id查询个人信息
 */
-(NSString *)getmydepartmentStr :(NSString *)InquireStr
{
   return  [[DBHelper sharedInstance]InquiretableName:infotableName InquireName:InquireStr knowStr:@"id" userid:Id];
}
//删除表
-(BOOL)deletetable
{
    return  [[DBHelper sharedInstance]deleteWithTable:infotableName];
}
//修改数据
-(BOOL)modifyupdateName:(NSString *)updataName newName:(NSString *)newName  userid:(NSString *)userid
{
    return [[DBHelper sharedInstance]executeUpdatedatafromtable:infotableName updateStr:updataName NewStr:newName userId:userid];
}

//查询指定行数据
-(void)getcellNumberData :(NSString *)cellNumber
{
    [[DBHelper sharedInstance]getcellrowdataTableName:infotableName cellID:cellNumber];
}
@end
